<?php

use think\migration\Migrator;
use think\migration\db\Column;

class StatSupplier extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('stat_supplier', ['comment' => '经销商统计表(日,30分执行一次)'])
             ->addColumn('supplier_id', 'integer', ['limit' => 11, 'default' => 0, "after" => 'id', 'comment' => '第三方ID'])
             ->addColumn('sales_amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, "after" => 'supplier_id', 'comment' => '销售金额'])
             ->addColumn('sales_quantity', 'integer', ['limit' => 11, 'default' => 0, "after" => 'sales_amount', 'comment' => '销售数量'])
             ->addColumn('order_quantity', 'integer', ['limit' => 11, 'default' => 0, "after" => 'sales_quantity', 'comment' => '订单数量'])
             ->addColumn('return_quantity', 'integer', ['limit' => 11, 'default' => 0, "after" => 'order_quantity', 'comment' => '退货数量'])
             ->addColumn('return_amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, "after" => 'return_quantity', 'comment' => '退货金额'])
             ->addColumn('collection_amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, "after" => 'return_amount', 'comment' => '回款金额'])
             ->addColumn('received_amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, "after" => 'collection_amount', 'comment' => '实收金额'])
             ->addColumn('bill_amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, "after" => 'received_amount', 'comment' => '账期金额'])
             ->addColumn('purchase_quantity', 'integer', ['limit' => 11, 'default' => 0, "after" => 'bill_amount', 'comment' => '采购数量'])
             ->addColumn('purchase_amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, "after" => 'purchase_quantity', 'comment' => '采购金额'])
             ->addColumn('purchase_order_quantity', 'integer', ['limit' => 11, 'default' => 0, "after" => 'purchase_amount', 'comment' => '采购订单数量'])
             ->addColumn('year', 'integer', ['limit' => 4, 'default' => 2024, "after" => 'purchase_order_quantity', 'comment' => '年'])
             ->addColumn('month', 'integer', ['limit' => 2, 'default' => 1, "after" => 'year', 'comment' => '月'])
             ->addColumn('quarter', 'integer', ['limit' => 1, 'default' => 1, "after" => 'month', 'comment' => '季度'])
             ->addColumn('type', 'integer', ['limit' => 1, 'default' => 3, "after" => 'quarter', 'comment' => '类型: 1:日,2:周,3:月,4:季,5:年'])
             ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'type', 'comment' => '1:正常,2:禁用'])
             ->addColumn('create_time', 'integer', ['limit' => 10, 'after' => 'status', 'default' => 0, 'comment' => '创建时间'])
             ->addColumn('update_time', 'integer', ['limit' => 10, 'after' => 'create_time', 'default' => 0, 'comment' => '更新时间'])
             ->addColumn('delete_time', 'integer', ['limit' => 10, 'after' => 'update_time', 'default' => 0, 'comment' => '删除时间'])
             ->addIndex('supplier_id', ['name' => 'supplier_id'])
             ->create();
    }
}
